package com.biz.primus.app.rest.controller.cart;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.CartFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.base.global.GlobalParams;
import com.biz.primus.model.cart.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ShopCartController
 *
 * @author JKLiues
 * @date 2017年11月14日
 */
@RestController
@RequestMapping("cart")
public class ShopCartController extends RestBaseController {
    private final CartFeignClient cartFeignClient;

    @Autowired
    public ShopCartController(CartFeignClient cartFeignClient) {
        this.cartFeignClient = cartFeignClient;
    }

    @ApiOperation(value = "购物车商品信息", response = ShopCartRespVo.class)
    @PostMapping("getShopCartInfo")
    public JsonResult getShopCartInfo(GlobalParams gp, @RequestBody CartBaseReqVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        ShopCartRespVo shopCartInfo = cartFeignClient.getShopCartInfo(reqVo);
        return new JsonResult(shopCartInfo);
    }

    @ApiOperation(value = "加入购物车", response = ShopCartRespVo.class)
    @PostMapping("addShopCartItem")
    public JsonResult addShopCartItem(GlobalParams gp, @RequestBody ShopCartItemAddVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        ShopCartRespVo result = cartFeignClient.addShopCartItem(reqVo);
        return new JsonResult(result);
    }

    @ApiOperation(value = "删除购物车商品")
    @PostMapping("deleteShopCartItems")
    public JsonResult deleteShopCartItems(GlobalParams gp, @RequestBody CartProductListVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        cartFeignClient.deleteShopCartItems(reqVo);
        return new JsonResult();
    }

    @ApiOperation("设置购物车选中商品")
    @PostMapping("selectedItem")
    public JsonResult selectedItem(GlobalParams gp, @RequestBody ShopCartItemCheckVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        cartFeignClient.selectedItem(reqVo);
        return new JsonResult();
    }

    @ApiOperation(value = "获取购物车商品数量", response = ShopCartNumRespVo.class)
    @PostMapping("getShopCartNum")
    public JsonResult getShopCartNum(GlobalParams gp, @RequestBody CartBaseReqVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        ShopCartNumRespVo shopCartNum = cartFeignClient.getShopCartNum(reqVo);
        return new JsonResult(shopCartNum);
    }
}